<template>
  <div class="app-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>设备管理</span>
        </div>
      </template>
      <div class="device-management">
        <el-table :data="deviceList" style="width: 100%">
          <el-table-column prop="name" label="设备名称" />
          <el-table-column prop="type" label="设备类型" />
          <el-table-column prop="location" label="安装位置" />
          <el-table-column prop="status" label="状态">
            <template #default="scope">
              <el-tag
                :type="scope.row.status === '正常' ? 'success' : 'danger'"
              >
                {{ scope.row.status }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template #default="scope">
              <el-button size="small" @click="handleEdit(scope.row)"
                >编辑</el-button
              >
              <el-button
                size="small"
                type="danger"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from "vue";

const deviceList = ref([
  { name: "1号变压器", type: "变压器", location: "配电室A", status: "正常" },
  { name: "2号水泵", type: "水泵", location: "泵房B", status: "正常" },
  { name: "3号发电机", type: "发电机", location: "机房C", status: "故障" },
  { name: "4号空调", type: "空调", location: "控制室D", status: "正常" },
]);

const handleEdit = (row) => {
  console.log("编辑设备", row);
};

const handleDelete = (row) => {
  console.log("删除设备", row);
};
</script>

<style lang="scss" scoped>
.device-management {
  padding: 20px;
}
</style>
